<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%@page import="beans.ClassBean"%>
<%@page import="java.util.List"%>
<%@page import="dao.MngClass"%>
<%@page import="dao.CheckAccount"%>

<html>
    <head>
        <script language="javascript">
            function delete1()
            {
                return confirm('Do you want delete this record');
            }
        </script>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Show Class Page</title>
        <style>                        
            table, th, td {
                border: 1px solid #619702;
                border-collapse: collapse;
                width:99.3% ;
            }
            th, td {
                padding: 5px;
                width: 100px;
            }
            th {
                text-align: center;
            }
        </style>
    </head>
    <body>  
        <%
            if (request.getAttribute("msg") != null) {
        %>
        <font color="green" > <%= request.getAttribute("msg")%> </font>
        <%
            }
            if (request.getAttribute("error") != null) {
        %>
        <font color="red" > <%= request.getAttribute("error")%> </font>
        <%
            }
            HttpSession ss_class = request.getSession();
            String roll_class = ss_class.getAttribute("roll").toString();
            String staff_id = ss_class.getAttribute("acc_id").toString();
            CheckAccount ck = new CheckAccount();
            MngClass mngClass = new MngClass();
            List<ClassBean> listClass = null;
            if (roll_class.equals("staff")) {
                listClass = mngClass.listClassByAccId(staff_id);
            } else if (roll_class.equals("admin")) {
                listClass = mngClass.showClass();
        %>
        <br><br><a href="index.jsp?page=create_class">Create new class</a> 
        <%
            }
        %>        
        <br><br>        
        <table>                
            <tr>
                <th>Staff</th>		
                <th>ClassName</th>
                <th>StartDate</th>
                <th>FinishDate</th>   
                <th>Description</th>   
                    <%
                        if (roll_class.equals("admin")) {
                    %>
                <th>Edit</th>
                <th>Delete</th>
                    <%
                        }
                        if (!roll_class.equals("admin")) {
                    %>               
                <th>View Student</th>
                    <%
                        }
                        if (roll_class.equals("staff")) {
                    %>
                <th>View Assignment</th>
                    <% }%>
            </tr> 
            <%  for (ClassBean classBean : listClass) {
                    if (classBean.getDescription() == null) {
                        classBean.setDescription("");
                    }
            %>
            <tr>  
                <th><%= ck.getFullName(classBean.getAcc_id())%></th>
                <th><%= classBean.getClass_name()%></th>
                <th><%= classBean.getStart_date()%></th>
                <th><%= classBean.getFinish_date()%></th>               
                <th><%= classBean.getDescription()%></th>
                    <%
                        if (roll_class.equals("admin")) {
                    %>
                <th>
            <form action="editClass" method ="get">
                <input type="hidden" name="action" value="update">
                <input type="hidden" name="class_id" value="<%= classBean.getClass_id()%>">
                <input type="hidden" name="acc_id" value="<%= classBean.getAcc_id()%>">                 
                <input type="hidden" name="class_name" value="<%= classBean.getClass_name()%>">
                <input type="hidden" name="start_date" value="<%= classBean.getStart_date()%>">
                <input type="hidden" name="finish_date" value="<%= classBean.getFinish_date()%>">   
                <input type="hidden" name="description" value="<%= classBean.getDescription()%>">   
                <input type="submit" value="Update">
            </form>
        </th>
        <th>
        <form action="editClass" method ="get">
            <input type="hidden" name="action" value="delete">
            <input type="hidden" name="class_id" value="<%= classBean.getClass_id()%>">
            <input type="submit" value="Delete" onclick='return delete1()'>
        </form>
    </th>
    <%
        }
        if (!roll_class.equals("admin")) {
    %>
    <th>
    <form action="viewClass" method ="get">        
        <input type="hidden" name="class_id" value="<%= classBean.getClass_id()%>">
        <input type="submit" value="View Student">
    </form>
</th>
<%
    }
    if (roll_class.equals("staff")) {
%>
<th>
<form action="viewAssign" method ="get">        
    <input type="hidden" name="class_id" value="<%= classBean.getClass_id()%>">
    <input type="submit" value="View Assignment">
</form></th>
<% }%>
</tr>   
<%
    }
%>
</table>
</body>
</html>
